package br.com.vti.sisp_sicrim.antigo.controller.relatorios;

import java.io.FileNotFoundException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import net.sf.jasperreports.engine.JRException;
import br.com.caelum.vraptor.Result;
import br.com.vti.sisp_sicrim.antigo.model.DidEmissao;
import br.com.vti.sisp_sicrim.antigo.model.SicCadnovo;
import br.com.vti.sisp_sicrim.antigo.model.SicTabelas;
import br.com.vti.sisp_sicrim.antigo.util.Relatorios;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe responsavel por encapsular o tratamento e as consistencias da tela
 * Scrppb04Report
 * 
 * @author Incode - Data: mai/2014
 * 
 */
public class Scrppb04Report {
	private String nomeClasse;
	private String jNomeide;
	private int dtini;
	private String tPosto;
	private int jCont1;
	private int jCont;
	private String dataCorrente;
	private int datini;
	private int datfim;
	private Long novoRegger; // DB
	private Integer novoMatfuncAtu; // DB
	public String descel1;
	public String desc1;
	public String desp1;
	public String desp3;
	public String desc2;
	private String nroPagina;
	private Result result;
	private Sessao sessao;
	private Relatorios report;
	// Classes views
	SicCadnovo sicCadnovoView = new SicCadnovo();
	SicTabelas vwDvetab = new SicTabelas();
	DidEmissao vwEmissao = new DidEmissao(); // Classes includes

	public Scrppb04Report() throws JRException, ParseException {
		inicializar();
	}

	public Scrppb04Report(Sessao sessao) throws JRException, ParseException {
		this.sessao = sessao;
		inicializar();
	}

	public void inicializar() throws JRException, ParseException {
		report = new Relatorios();
		nomeClasse = this.getClass().getSimpleName();
		jNomeide = "";
		dtini = 0;
		jCont1 = 0;
		jCont = 0;
		datini = 0;
		datfim = 0;
		dataCorrente = new SimpleDateFormat("dd/MM/yyyy").format(Calendar.getInstance().getTime()); // *DATE
		report.setNumeroRel(1, "C");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 2, "lit_1_2", "C", "", "  ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 3);
			{
				report.adicionaCampo(1, 62, "lit_1_62", "C", "", "* GEJUSPC - GERENCIA DA JUSTICA, SEGURANCA PUBLICA E CIDADANIA");
				report.adicionaCampo(110, 9, "lit_110_9", "C", "", "PAGINA..:");
				report.adicionaCampo(120, 5, "nroPagina", "S", "Z.ZZ9", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(3, 3);
			{
				report.adicionaCampo(1, 60, "lit_1_60", "C", "", "* STI- SUBGERENCIA DE TECNOLOGIA DA INFORMCAO - VIVA CIDADAO");
				report.adicionaCampo(110, 9, "lit_110_9", "C", "", "DATA....:");
				report.adicionaCampo(120, 10, "dataCorrente", "S", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(4, 1);
			{
				report.adicionaCampo(1, 30, "lit_1_30", "C", "", "* INSTITUICAO DE IDENTIFICACAO");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(5, 6);
			{
				report.adicionaCampo(1, 36, "lit_1_36", "C", "", "* ATESTADOS DE ANTECEDENTES EMITIDOS");
				report.adicionaCampo(10, 9, "lit_10_9", "C", "", "PERIODO: ");
				report.adicionaCampo(20, 8, "Datini", "N", "99/99/9999", "");
				report.adicionaCampo(29, 2, "lit_29_2", "C", "", " -");
				report.adicionaCampo(32, 8, "Datfim", "N", "99/99/9999", "");
				report.adicionaCampo(110, 18, "lit_110_18", "C", "", "PROGRAMA: SCRPPB04");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(6, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(7, 5);
			{
				report.adicionaCampo(1, 11, "lit_1_11", "C", "", "REG. GERAL.");
				report.adicionaCampo(16, 17, "lit_16_17", "C", "", "NOME DO INDIVIDUO");
				report.adicionaCampo(59, 10, "lit_59_10", "C", "", "DAT. EMISS");
				report.adicionaCampo(72, 7, "lit_72_7", "C", "", "MAT.FUN");
				report.adicionaCampo(81, 5, "lit_81_5", "C", "", "POSTO");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(8, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(2, "D");
		{
			report.setNumeroLinhaRel(1, 5);
			{
				report.adicionaCampo(1, 13, "Novoregger", "N", "ZZZZZZZZZZZZ-Z", "");
				report.adicionaCampo(16, 40, "Jnomeide", "X", "", "");
				report.adicionaCampo(59, 8, "Dtini", "N", "99/99/9999", "");
				report.adicionaCampo(72, 7, "Novomatfuncatu", "N", "ZZZZZZ9", "");
				report.adicionaCampo(81, 3, "TPosto", "N", "", "");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(3, "D");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 2);
			{
				report.adicionaCampo(1, 43, "lit_1_43", "C", "", "*** TOTAL GERAL DE REGISTROS PROCESSADOS = ");
				report.adicionaCampo(45, 4, "Jcont1", "N", "ZZZ9", "");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(4, "D");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 4);
			{
				report.adicionaCampo(1, 35, "lit_1_35", "C", "", "*** TOTAL DE ATESTADOS EMITIDOS EM ");
				report.adicionaCampo(37, 8, "Dtini", "N", "99/99/9999", "");
				report.adicionaCampo(46, 3, "lit_46_3", "C", "", " = ");
				report.adicionaCampo(50, 4, "Jcont", "N", "99/99/9999", "");
				report.setFimLinhaRel();
			}
		}
		setDataCorrente(dataCorrente);
	}

	public boolean validar() {
		// validar os campos recebidos da tela
		return true;
	}

	public String getNomeClasse() {
		return nomeClasse;
	}

	public void setNomeClasse(String nomeClasse) throws ParseException {
		this.nomeClasse = nomeClasse;
		report.adicionaValorReport("Program", nomeClasse);
	}

	public String getJnomeide() {
		return jNomeide;
	}

	public void setJnomeide(String jNomeide) throws ParseException {
		this.jNomeide = jNomeide;
		report.adicionaValorReport("Jnomeide", jNomeide);
	}

	public int getDtini() {
		return dtini;
	}

	public void setDtini(int dtini) throws ParseException {
		this.dtini = dtini;
		report.adicionaValorReport("Dtini", dtini);
	}

	public String getTPosto() {
		return tPosto;
	}

	public void setTPosto(String tPosto) throws ParseException {
		this.tPosto = tPosto;
		report.adicionaValorReport("TPosto", tPosto);
	}

	public int getJcont1() {
		return jCont1;
	}

	public void setJcont1(int jCont1) throws ParseException {
		this.jCont1 = jCont1;
		report.adicionaValorReport("Jcont1", jCont1);
	}

	public int getJcont() {
		return jCont;
	}

	public void setJcont(int jCont) throws ParseException {
		this.jCont = jCont;
		report.adicionaValorReport("Jcont", jCont);
	}

	public int getDatini() {
		return datini;
	}

	public void setDatini(int datini) throws ParseException {
		this.datini = datini;
		report.adicionaValorReport("Datini", datini);
	}

	public int getDatfim() {
		return datfim;
	}

	public void setDatfim(int datfim) throws ParseException {
		this.datfim = datfim;
		report.adicionaValorReport("Datfim", datfim);
	} // /

	public String getDescel1() {
		return this.desc1 + this.desp1 + this.tPosto + this.desp3 + this.desc2;
	}

	public void setDescel1(String descel1) throws ParseException {
		this.descel1 = descel1;
		this.desc1 = UtilBean.subStr(descel1, 0, 30);
		report.adicionaValorReport("Desc1", UtilBean.subStr(descel1, 0, 30));
		this.desp1 = UtilBean.subStr(descel1, 30, 8);
		report.adicionaValorReport("Desp1", UtilBean.subStr(descel1, 30, 8));
		this.tPosto = UtilBean.subStr(descel1, 38, 3);
		report.adicionaValorReport("TPosto", UtilBean.subStr(descel1, 38, 3));
		this.desp3 = UtilBean.subStr(descel1, 41, 3);
		report.adicionaValorReport("Desp3", UtilBean.subStr(descel1, 41, 3));
		this.desc2 = UtilBean.subStr(descel1, 44, 16);
		report.adicionaValorReport("Desc2", UtilBean.subStr(descel1, 44, 16));
	}

	public String getNroPagina() {
		return nroPagina;
	}

	public void setNroPagina(String nroPagina) throws ParseException {
		this.nroPagina = nroPagina;
		report.adicionaValorReport("nroPagina", nroPagina);
	}

	public String getDataCorrente() {
		return dataCorrente;
	}

	public void setDataCorrente(String dataCorrente) throws ParseException {
		this.dataCorrente = dataCorrente;
		report.adicionaValorReport("dataCorrente", dataCorrente);
	}

	public void setPageSize(int pagesize) throws JRException {
		report.setPageSize(pagesize);
	}

	public void setLineSize(int linesize) {
		report.setLineSize(linesize);
	}

	public int getPageSize() {
		return report.getPageSize();
	}

	public int getPageLine() {
		return report.getPageLine();
	}

	public void saltaLinhas(int qtdLinhas) throws ParseException, JRException {
		report.saltaLinhas(qtdLinhas);
	}

	public void gravaRelatorio(int nroRel) throws ParseException, JRException {
		setNroPagina(String.valueOf(report.getPageNumber()));
		report.gravaRelatorio(report, nroRel, false);
	}

	public void imprimir() throws FileNotFoundException, JRException {
		report.imprimir();
	}

	public Long getNovoRegger() {
		return novoRegger;
	}

	public void setNovoRegger(Long novoRegger) throws ParseException {
		this.novoRegger = novoRegger;
		report.adicionaValorReport("novoRegger", novoRegger);
	}

	public Integer getNovoMatfuncAtu() {
		return novoMatfuncAtu;
	}

	public void setNovoMatfuncAtu(Integer novoMatfuncAtu) throws ParseException {
		this.novoMatfuncAtu = novoMatfuncAtu;
		report.adicionaValorReport("novoMatfuncAtu", novoMatfuncAtu);
	}

}
